<?php
include_once("_common.php");
include_once("$mw_cash[path]/cybercash.lib.php");

if (!$is_member)
    alert_close("로그인 후 이용해주세요.");

//if ($is_admin) $paytype = "cyber";

set_session("cash_membership", false);

switch($paytype) {
    case "account": $title = "무통장입금"; break;
    //case "cyber": $title = "무통장입금-가상계좌"; break;
    case "card": $title = "신용카드 결제"; break;
    case "bank": $title = "계좌이체"; break;
    case "hp": $title = "핸드폰결제"; break;
    case "paypal": $title = "페이팔 결제"; break;
    default:
	alert_close("결제방법이 잘못되었습니다.");
}

if ($paytype == 'paypal' && $mw_cash[cf_paypal_foreign] && mw_cash_is_korea() && !$is_admin) {
    alert_close("해외에서만 페이팔 결제가 가능합니다.");
}

if ($paytype == "account")
    $charge_min = $mw_cash[cf_charge_min];
else
    $charge_min = $mw_cash[cf_card_min];

if ($mw_cash[cf_tax])
    $charge_min *= 1.1;

$is_paypal = false;
if ($mw_cash[cf_paypal] && $paytype == 'paypal') {
    $is_paypal = true;
}

$g4[title] = "$mw_cash[cf_cash_name] 충전";
include_once("$g4[path]/head.sub.php");
?>

<style type="text/css">
body { padding:10px; }
h3 { font-size:15px; }
.account-info { border:5px solid #efefef; padding:20px; font-weight:bold; text-align:center; font-size:13px; }
td.head { border-bottom:1px solid #ddd; padding:10px 10px 0 0; font-weight:bold; }
td.body { border-bottom:1px solid #ddd; padding:10px; }
.btn1 { background-color:#efefef; cursor:pointer; }
.hints { color:#888; margin:5px 0 5px 0; }
#payment-info { font-weight:bold; color:#0D6AB2; font-size:13px; }
</style>

<script type="text/javascript">
<? if ($is_paypal) { ?>
function how_much_cash_charge() {
    var cash = parseInt(fwrite.ac_cash.value);
    //var pay = Math.round(cash * <?=$mw_cash[cf_paypal_dollar]?> * 100) / 100;

    if (!cash) cash = 0;

    pay = cash * <?=$mw_cash[cf_paypal_dollar]?>;

    //if (pay > 0.00)
	html = "" + pay + " $";
    //else html = "0.01 달라 이상 입력해주세요";

    document.fwrite.payment.value = pay;
    document.getElementById("payment-info").innerHTML = html;
}
<? } else { ?>
function how_much_cash_charge() {
    var cash = parseInt(fwrite.ac_cash.value);
    var pay = Math.round(cash * <? echo $mw_cash[cf_tax] ? $mw_cash[cf_cash_price] * 1.1 : $mw_cash[cf_cash_price]; ?>);

    if (pay > 0)
	html = "" + number_format("" + pay) + " 원";
    else
	html = "숫자만 입력해주세요.";

    document.fwrite.payment.value = pay;
    document.getElementById("payment-info").innerHTML = html;
}
<? } ?>

function form_check() {
    var f = document.fwrite;
    if (!f.onsubmit()) return;

    if (!confirm("충전신청 하시겠습니까?"))
	return; 

    <? if ($charge_min && !$is_paypal) { ?>
    if (f.payment.value < <?=$charge_min?>) {
	alert("<?=number_format($charge_min)?>원 (부가세포함) 이상 충전하실 수 있습니다.");	
	return;
    }
    <? } ?>

    f.submit();
}
</script>

<form name="fwrite" method="post" action="cash-charge-update.php" autocomplete="off">
<input type="hidden" name="paytype" value="<?=$paytype?>">
<input type="hidden" name="payment" value="<?=$payment?>">

<h3> <img src="img/icon_cash.gif" align="absmiddle"> <?=$g4[title]?> </h3>


<div class="account-info">
    <? if ($paytype == "account") { ?>
	입금계좌 : <?=$mw_cash[cf_account_num]?>
    <? } else echo $title; ?>
</div>

<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
<colgroup width="100"/>
<colgroup width=""/>
<? if ($paytype == "account") { ?>
<tr>
    <td class="head" valign="top"> 입금자 성명 </td>
    <td class="body">
	<input type="text" size="20" name="ac_name" required itemname="입금자 성명" value="<?=$member[mb_name]?>" class="ed">
	<div class="hints">입금하시는 분의 성함을 입력해주세요.</div>
	<div class="hints">실제 입금자 성명과 다를 경우 <?=$mw_cash[cf_cash_name]?> 충전이 어렵습니다.</div>
    </td>
</tr>
<tr>
    <td class="head" valign="top"> 핸드폰 번호 </td>
    <td class="body">
	<input type="text" size="20" name="ac_hp" telnumber required itemname="입금자 성명" value="<?=$member[mb_hp]?>" class="ed">
	<div class="hints">충전완료통보 받을 핸드폰 번호를 입력해주세요.("-" 포함)</div>
    </td>
</tr>
<? } ?>

<?/* if ($paytype == "bank" && $mw_cash[cf_pg] == "lgdacom") { // 계좌이체 ?>
<tr>
    <td class="head" valign="top"> 주민등록번호 </td>
    <td class="body">
	<input type="text" size="20" maxlength="13" minlength="13" name="pid" required itemname="주민등록번호" class="ed">
	<div class="hints">'-' 기호 없이 숫자만 입력해주세요.</div>
	<div class="hints">계좌이체는 주민등록번호를 필요로 합니다.</div>
	<div class="hints">본인확인 절차로만 사용되며 DB에 저장하지 않습니다.</div>
    </td>
</tr>
<? }*/ ?>

<tr>
    <td class="head" valign="top"> <?=$mw_cash[cf_cash_name]?> 충전 </td>
    <td class="body">
	<input type="text" size="10" name="ac_cash" required numeric itemname="<?=$mw_cash[cf_cash_name]?>" value="" class="ed" onkeydown="if (event.keyCode==13) return false;" onkeyup="how_much_cash_charge()">
	<?=$mw_cash[cf_cash_unit]?>
	<div class="hints">충전하고자 하는 <?=$mw_cash[cf_cash_name]?> 수를 입력해주세요.</div>
        <? if ($is_paypal) { ?>
            <div class="hints"><?="$mw_cash[cf_cash_name] 1$mw_cash[cf_cash_unit] 당 ".number_format($mw_cash[cf_paypal_dollar], 5)." $"?> 입니다.</div>
        <? } else { ?>
            <div class="hints"><?="$mw_cash[cf_cash_name] 1$mw_cash[cf_cash_unit] 당 ".number_format(mw_get_payment($mw_cash[cf_cash_price], $mw_cash[cf_tax]))." 원"?>
            <? if ($mw_cash[cf_tax]) echo "(부가세 포함)"; ?> 입니다.</div>
            <? if ($paytype == "account" && $mw_cash[cf_charge_min]) { ?>
            <div class="hints">무통장 최소충전금액은 <?=number_format(mw_get_payment($mw_cash[cf_charge_min], $mw_cash[cf_tax]))?> 원 <? if ($mw_cash[cf_tax]) echo "(부가세 포함)"; ?> 입니다.</div>
            <? } ?>
            <? if ($paytype != "account" && $mw_cash[cf_card_min]) { ?>
            <div class="hints"><?=mw_get_paytype($paytype)?> 최소충전금액은 <?=number_format(mw_get_payment($mw_cash[cf_card_min], $mw_cash[cf_tax]))?> 원 <? if ($mw_cash[cf_tax]) echo "(부가세 포함)"; ?> 입니다.</div>
            <? } ?>
        <? } ?>
    </td>
</tr>
<tr>
    <td class="head" valign="top"> 결제 금액 </td>
    <td class="body">
        <? if ($is_paypal) { ?>
	<span id="payment-info">0 $</span>&nbsp;
        <? } else { ?>
	<span id="payment-info">0 원</span>&nbsp;
        <? } ?>

        <? if ($mw_cash[cf_happybean]) { ?>
        <div class="hints"> 결제하신 금액의 <?=$mw_cash[cf_happybean]?>% 해피빈에 기부합니다.  </div>
        <? } ?>
    </td>
</tr>
<? if ($paytype == "account") { ?>
<tr>
    <td class="head" valign="top"> 하실 말씀 </td>
    <td class="body">
	<textarea style="width:100%; height:50px;" name="ac_memo" itemname="하실 말씀" class="ed"></textarea>
	<div class="hints">관리자에게 하실 말씀이 있으시면 입력해주세요.</div>
    </td>
</tr>
<? } ?>
</table>

<div style="text-align:center; margin:20px 0 10px 0;">
<input type="button" value="확     인" class="btn1" onclick="form_check()">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="취     소" class="btn1" onclick="self.close()">
</div>

</form>

<?
include_once("$g4[path]/tail.sub.php");
